package se.teamscape.client.view;

import java.util.HashMap;

import se.teamscape.client.presenter.NavigationPresenter;

import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Hyperlink;

/**
 * View for site navigation that presents hyperlinks in
 * different categories.
 * 
 * We use DisclosurePanel for each category, which allows support
 * for show/hide on category content.
 * 
 * We will add CSS and images later to make a fancy navigation menu.
 * 
 * @author Andreas Borglin
 * 
 */
public class NavigationView extends BaseView implements NavigationPresenter.Display {

    private FlowPanel mPanel;
    private HashMap<String, DisclosurePanel> mCategories;

    public NavigationView() {

    }

    @Override
    public void init() {

        mCategories = new HashMap<String, DisclosurePanel>();
        mPanel = new FlowPanel();
        initWidget(mPanel);

    }

    @Override
    public void addCategory(String name, boolean expanded) {

        DisclosurePanel catPanel = new DisclosurePanel();
        catPanel.setHeader(new HTML(name));
        catPanel.setOpen(expanded);

        mCategories.put(name, catPanel);
        mPanel.add(catPanel);
    }

    @Override
    public void addLink(String category, String name, String token) {

        DisclosurePanel catPanel = mCategories.get(category);
        if (catPanel != null) {
            catPanel.add(new Hyperlink(name, token));
        }

    }
}
